/*
 * jdbc-trace-wrapper
 * Copyright (C) 2010. The jdbc-trace-wrapper Project
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package nz.jdbcwrapper;

import com.sybase.jdbcx.SybCallableStatement;
import com.sybase.jdbcx.SybMessageHandler;

import java.math.BigDecimal;
import java.sql.SQLException;


class WrapperSybCallableStatement extends WrapperCallableStatement
  implements SybCallableStatement
{
  final SybCallableStatement sybCallableStatement;

  public WrapperSybCallableStatement(Data data,
                              Statistic statistic,
                              SybCallableStatement sybCallableStatement)
  {
    super(data, statistic, sybCallableStatement);
    this.sybCallableStatement = sybCallableStatement;  // Same object as parent class holds
  }

  public void setParameterName(int i, String s)
  {
    long key = 0L;

    if (data.trace >= 4)
      key = Util.traceBegin(prefix + " setParameterName(" + i + ", " + s + ")");

    sybCallableStatement.setParameterName(i, s);

    if (data.trace >= 4)
      Util.traceEnd(key, (String)null);

    checkWarnings();
  }
  public void setBigDecimal(int i, BigDecimal bd, int i2, int i3) throws SQLException
  {
    long key = 0L;

    if (data.trace >= 4)
      key = Util.traceBegin(prefix + " setBigDecimal(" + i + ", " + bd + ", " + i2 + ", " + i3 + ")");

    try
    {
      sybCallableStatement.setBigDecimal(i, bd, i2, i3);

      if (data.trace >= 4)
        Util.traceEnd(key, (String)null);
    }
    catch (SQLException e)
    {
      if (data.trace >= 4)
        Util.traceEnd(key, e);
      throw e;
    }
    finally
    {
      checkWarnings();
    }
  }
  public void setSybMessageHandler(SybMessageHandler handler)
  {
    long key = 0L;

    if (data.trace >= 4)
      key = Util.traceBegin(prefix + " setSybMessageHandler(handler)");

    sybCallableStatement.setSybMessageHandler(handler);

    if (data.trace >= 4)
      Util.traceEnd(key, (String)null);
    checkWarnings();
  }
  public SybMessageHandler getSybMessageHandler()
  {
    long key = 0L;

    if (data.trace >= 3)
      key = Util.traceBegin(prefix + " getParameterMetaData()");

    SybMessageHandler result = sybCallableStatement.getSybMessageHandler();

    if (data.trace >= 3)
      Util.traceEnd(key, Util.toString(result));

    checkWarnings();
    return result;
  }
}

